﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RWXMLEdit.Common
{
    public static class WaggonNumberHelper
    {
        public static List<WaggonUicCountryCode> GetWaggonUicCountryCode()
        {
            return InitWaggonUicCountryCode();
        }

        public static List<WaggonTypeCode> GetWaggonTypeCode()
        {
            return InitWaggonTypeCode();
        }

        #region InitWaggonUicCountryCode.

        private static List<WaggonUicCountryCode> InitWaggonUicCountryCode()
        {
            List<WaggonUicCountryCode> list = new List<WaggonUicCountryCode>();

            list.Add(new WaggonUicCountryCode(10, "VR", "Valtionrautatiet", "FIN", "Finland"));
            list.Add(new WaggonUicCountryCode(12, "TF", "Transfesa (cargo waggon pool)", "", ""));
            list.Add(new WaggonUicCountryCode(14, "CIWL", "Compagnie Internationale des Wagons-Lits", "", ""));
            list.Add(new WaggonUicCountryCode(19, "ENR", "European Night Services", "", ""));
            list.Add(new WaggonUicCountryCode(20, "RZD", "Rossije Zeleznyje Dorogi", "RUS", "Russia"));
            list.Add(new WaggonUicCountryCode(21, "BCZ", "Bielorusse Zeleznue Dorogi", "BLR", "Belarus"));
            list.Add(new WaggonUicCountryCode(22, "UZ", "Ukr Zaliznyza", "UA", "Ukraine"));
            list.Add(new WaggonUicCountryCode(23, "CFM", "Caile Ferate Moldova", "MD", "Moldova"));
            list.Add(new WaggonUicCountryCode(24, "LG", "Lietuvos Gelezinkeliu", "LT", "Lithuania"));
            list.Add(new WaggonUicCountryCode(25, "LDZ", "Latvijas Dzelzcels", "LV", "Latvia"));
            list.Add(new WaggonUicCountryCode(26, "EVR", "Eesti Vabariigi Raudtee", "EST", "Estonia"));
            list.Add(new WaggonUicCountryCode(27, "KTZ", "Kazakhstan", "KZ", "Kazakhstan"));
            list.Add(new WaggonUicCountryCode(28, "GR", "Georgia", "GE", "Georgia"));
            list.Add(new WaggonUicCountryCode(29, "SAZ", "Uzbekistan", "UZ", "Uzbekistan"));

            list.Add(new WaggonUicCountryCode(30, "KNDR", "Zosun Minzuzui Inmingonghoagug", "PRK", "North Korea"));
            list.Add(new WaggonUicCountryCode(31, "MNR", "Mongolin Tomor Zam", "MGL", "Mongolia"));
            list.Add(new WaggonUicCountryCode(32, "DSVN", "Dung Sat Viet-Nam", "VN", "Vietnam"));
            list.Add(new WaggonUicCountryCode(33, "KNR", "Zhung Guo Tie Lu", "RC", "China"));
            list.Add(new WaggonUicCountryCode(34, "TRAVYS", "Transports Vallée de Joux, Yverdon-les-Bains, Ste. Croix", "", ""));
            list.Add(new WaggonUicCountryCode(34, "StLB", "Steiermärkische Landesbahnen", "", ""));
            list.Add(new WaggonUicCountryCode(35, "TRN", "Transports Régionaux Neuchâteloises", "", ""));
            list.Add(new WaggonUicCountryCode(36, "CJ", "Chemins de fer du Jura, Transports Publics Fribourgeois", "", ""));
            list.Add(new WaggonUicCountryCode(37, "TMR", "Transports de Martigny et Régions SA", "", ""));
            list.Add(new WaggonUicCountryCode(37, "WLB", "Wiener Lokalbahnen", "", ""));
            list.Add(new WaggonUicCountryCode(38, "RM", "Regionalverkehr Mittelland", "", ""));
            list.Add(new WaggonUicCountryCode(39, "LSE", "Luzern-Stans-Engelberg", "", ""));

            list.Add(new WaggonUicCountryCode(41, "HSH", "Hekurudhe e Shqiperise", "AL", "Albania"));
            list.Add(new WaggonUicCountryCode(42, "JR", "Japan Rail", "J", "Japan"));
            list.Add(new WaggonUicCountryCode(43, "GySEV", "Györ-Sopron-Ebenfurthi Vasutak", "", ""));
            list.Add(new WaggonUicCountryCode(44, "ZRS", "Zeljeznice Republice Srpske", "BIH", "Republika Srpska, Bosnia and Herzegovina"));
            list.Add(new WaggonUicCountryCode(45, "SZU", "Sihltal-Zürich-Üetliberg", "", ""));
            list.Add(new WaggonUicCountryCode(45, "GKE", "Graz-Köflacher Eisenbahn", "", ""));
            list.Add(new WaggonUicCountryCode(46, "MThB", "Mittelthurgaubahn", "", ""));
            list.Add(new WaggonUicCountryCode(47, "THURBO", "SBB-CFF-FFS Thurgau", "", ""));
            list.Add(new WaggonUicCountryCode(48, "SOB", "Schweizerische Südostbahn", "", ""));
            list.Add(new WaggonUicCountryCode(49, "RHB", "Rhätische Bahn", "", ""));

            list.Add(new WaggonUicCountryCode(50, "ZFBH", "Zeljeznice Federacije Bosne i Hercegovine", "BIH", "Federation of Bosnia and Herzegovina"));
            list.Add(new WaggonUicCountryCode(51, "PKP", "Polskie Koleje Panstwowe", "PL", "Poland"));
            list.Add(new WaggonUicCountryCode(52, "BDZ", "Bulgarski Durzavni Zeleznici", "BG", "Bulgaria"));
            list.Add(new WaggonUicCountryCode(53, "CFR", "Cailor Ferate Romane", "RO", "Romania"));
            list.Add(new WaggonUicCountryCode(54, "CD", "Ceske Drahy", "CZ", "Czech Republic"));
            list.Add(new WaggonUicCountryCode(55, "MAV", "Magyar Allamvasutak", "H", "Hungary"));
            list.Add(new WaggonUicCountryCode(56, "ZSR", "Zeleznice Slovenskej Republiky", "SK", "Slovakia"));
            list.Add(new WaggonUicCountryCode(57, "AZ", "Azerbadijan", "AZE", "Azerbaijan"));
            list.Add(new WaggonUicCountryCode(58, "ARM", "Armenia", "ARM", "Armenia"));
            list.Add(new WaggonUicCountryCode(59, "KRG", "Kyrgyzstan", "KS", "Kyrgyzstan"));

            list.Add(new WaggonUicCountryCode(60, "IE", "Iarnrod Eireann", "IRL", "Ireland"));
            list.Add(new WaggonUicCountryCode(61, "KNR", "Korea National Railroad", "ROK", "South Korea"));
            list.Add(new WaggonUicCountryCode(62, "SP", "Schweizerische Privatbahnen", "", ""));
            list.Add(new WaggonUicCountryCode(63, "BLS", "Lötschbergbahn", "", ""));
            list.Add(new WaggonUicCountryCode(64, "FNM", "Ferrovie Nord-Milano", "", ""));
            list.Add(new WaggonUicCountryCode(65, "MZ", "Macedonskih Zeleznica", "MK", "Macedonia"));
            list.Add(new WaggonUicCountryCode(66, "TZD", "Tajikistan", "TJ", "Tajikistan"));
            list.Add(new WaggonUicCountryCode(67, "TRK", "Turkmenistan", "TM", "Turkmenistan"));
            list.Add(new WaggonUicCountryCode(68, "BE AEE", "Ahaus-Enscheder Eisenbahn", "", ""));
            list.Add(new WaggonUicCountryCode(69, "ET", "Eurotunnel", "", ""));

            list.Add(new WaggonUicCountryCode(70, "BR", "British Railways", "GB", "United Kingdom"));
            list.Add(new WaggonUicCountryCode(71, "RENFE", "Red Nacional de los Ferrocariles Españoles", "E", "Spain"));
            list.Add(new WaggonUicCountryCode(72, "JZ", "Zajednica Jugoslovenskih Zeleznica", "SRB", "Serbia"));
            list.Add(new WaggonUicCountryCode(73, "OSE", "Grekland Organismos Sidirodromon Ellados", "GR", "Greece"));
            list.Add(new WaggonUicCountryCode(74, "SJ", "Statens Järnvägar", "S", "Sweden"));
            list.Add(new WaggonUicCountryCode(75, "TCDD", "Türkiye Cumhuriyeti Devlet Demiryollari", "TR", "Turkey"));
            list.Add(new WaggonUicCountryCode(76, "NSB", "Norges Statsbaner", "N", "Norway"));
            list.Add(new WaggonUicCountryCode(78, "HZ", "Hrvatske Zeljeznice", "HR", "Croatia"));
            list.Add(new WaggonUicCountryCode(79, "SZ", "Slovenske Zeleznice", "SLO", "Slovenia"));

            list.Add(new WaggonUicCountryCode(80, "DB", "Deutsche Bahn AG", "D", "Germany"));
            list.Add(new WaggonUicCountryCode(81, "ÖBB", "Österreichische Bundesbahnen", "A", "Austria"));
            list.Add(new WaggonUicCountryCode(82, "CFL", "Societe Nationale des Chemins de Fer Luxemburgeois", "L", "Luxembourg"));
            list.Add(new WaggonUicCountryCode(83, "FS", "Ferrovie dello Stato", "I", "Italy"));
            list.Add(new WaggonUicCountryCode(84, "NS", "Nederlandse Spoorwegen", "NL", "Netherlands"));
            list.Add(new WaggonUicCountryCode(85, "SBB CFF FFS", "Schweizerische Bundesbahnen", "CH", "Switzerland"));
            list.Add(new WaggonUicCountryCode(86, "DSB", "Danske Statsbaner", "DK", "Denmark"));
            list.Add(new WaggonUicCountryCode(87, "SNCF", "Societe Nationale des Chemins de fer Francais", "F", "France"));
            list.Add(new WaggonUicCountryCode(88, "SNCB", "Societe Nationale des Chemins de fer Belges", "B", "Belgium"));

            list.Add(new WaggonUicCountryCode(90, "ER", "Egypt Railways", "ET", "Egypt"));
            list.Add(new WaggonUicCountryCode(91, "SNCFT", "Societe Nationale des Chemins de fer Tunisiens", "TN", "Tunisia"));
            list.Add(new WaggonUicCountryCode(92, "SNTF", "Societe Nationale des Transports Ferroviaires", "DZ", "Algeria"));
            list.Add(new WaggonUicCountryCode(93, "ONCFM", "Office National des Chemins de fer du Maroc", "MA", "Morocco"));
            list.Add(new WaggonUicCountryCode(94, "CP", "Caminhos de Ferro Portugueses", "P", "Portugal"));
            list.Add(new WaggonUicCountryCode(95, "IR", "Israel Railways", "IL", "Israel"));
            list.Add(new WaggonUicCountryCode(96, "RAI", "Rahahane Djjomhouriye Eslami Iran", "IR", "Iran"));
            list.Add(new WaggonUicCountryCode(97, "CFS", "Administration Generale des Chemins de Fer Syriens", "SYR", "Syria"));
            list.Add(new WaggonUicCountryCode(98, "CEL", "Office des Chemins de fer de l'Etat Libanais", "RL", "Lebanon"));
            list.Add(new WaggonUicCountryCode(99, "IRR", "Iraqi Republic Railways Establishment", "IRQ", "Iraq"));
            list.Add(new WaggonUicCountryCode(00, "NIR", "Northern Ireland Railways", "", ""));

            return list;
        }
        
        #endregion

        private static List<WaggonTypeCode> InitWaggonTypeCode()
        {
            List<WaggonTypeCode> list = new List<WaggonTypeCode>();

            list.Add(new WaggonTypeCode(1, "RIV-EUROP", "2-3 axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(2, "RIV-EUROP", "2-3 axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(3, "RIV-EUROP", "2-3 axlar, privatägd"));
            list.Add(new WaggonTypeCode(4, "RIV-EUROP", "2-3 axlar, privatägd"));
            list.Add(new WaggonTypeCode(5, "RIV-EUROP", "2-3 axlar, hyrvagn"));
            list.Add(new WaggonTypeCode(6, "RIV-EUROP", "2-3 axlar, hyrvagn"));

            list.Add(new WaggonTypeCode(11, "RIV-EUROP", "4 eller fler axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(12, "RIV-EUROP", "4 eller fler axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(13, "RIV-EUROP", "4 eller fler axlar, privatägd"));
            list.Add(new WaggonTypeCode(14, "RIV-EUROP", "4 eller fler axlar, privatägd"));
            list.Add(new WaggonTypeCode(15, "RIV-EUROP", "4 eller fler axlar, hyrvagn"));
            list.Add(new WaggonTypeCode(16, "RIV-EUROP", "4 eller fler axlar, hyrvagn"));

            list.Add(new WaggonTypeCode(21, "RIV", "2-3 axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(22, "RIV", "2-3 axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(23, "RIV", "2-3 axlar, privatägd"));
            list.Add(new WaggonTypeCode(24, "RIV", "2-3 axlar, privatägd"));
            list.Add(new WaggonTypeCode(25, "RIV", "2-3 axlar, hyrvagn"));
            list.Add(new WaggonTypeCode(26, "RIV", "2-3 axlar, hyrvagn"));

            list.Add(new WaggonTypeCode(31, "RIV", "4 eller fler axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(32, "RIV", "4 eller fler axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(33, "RIV", "4 eller fler axlar, privatägd"));
            list.Add(new WaggonTypeCode(34, "RIV", "4 eller fler axlar, privatägd"));
            list.Add(new WaggonTypeCode(35, "RIV", "4 eller fler axlar, hyrvagn"));
            list.Add(new WaggonTypeCode(36, "RIV", "4 eller fler axlar, hyrvagn"));

            list.Add(new WaggonTypeCode(40, "", "2-3 axlar, servicevagn"));

            list.Add(new WaggonTypeCode(41, "", "2-3 axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(42, "", "2-3 axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(43, "", "2-3 axlar, privatägd"));
            list.Add(new WaggonTypeCode(44, "", "2-3 axlar, privatägd"));
            list.Add(new WaggonTypeCode(45, "", "2-3 axlar, hyrvagn"));
            list.Add(new WaggonTypeCode(46, "", "2-3 axlar, hyrvagn"));

            list.Add(new WaggonTypeCode(80, "", "4 eller fler axlar, servicevagn"));

            list.Add(new WaggonTypeCode(81, "", "4 eller fler axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(82, "", "4 eller fler axlar, järnvägsägd"));
            list.Add(new WaggonTypeCode(83, "", "4 eller fler axlar, privatägd"));
            list.Add(new WaggonTypeCode(84, "", "4 eller fler axlar, privatägd"));
            list.Add(new WaggonTypeCode(85, "", "4 eller fler axlar, hyrvagn"));
            list.Add(new WaggonTypeCode(86, "", "4 eller fler axlar, hyrvagn"));

            return list;
        }
    }

    public class WaggonTypeCode
    {
        public WaggonTypeCode(int number, string riv, string text)
        {
            Number = number;
            Riv = riv;
            Text = text;
        }
        
        public int Number { get; set; }
        public string Riv { get; set; }
        public string Text { get; set; }

        public override string ToString()
        {
            return string.Format("{0:0#} {1} - {2}", Number, Riv, Text);
        }
    }

    public class WaggonUicCountryCode
    {
        public WaggonUicCountryCode(int numericalCode, string companyCode, string company, string countryCode, string country)
        {
            NumericalCode = numericalCode;
            CompanyCode = companyCode;
            Company = company;
            CountryCode = countryCode;
            Country = country;
        }

        public int NumericalCode { get; set; }
        public string CompanyCode { get; set; }
        public string Company { get; set; }
        public string CountryCode { get; set; }
        public string Country { get; set; }

        public override string ToString()
        {
            return string.Format("{0:0#} {1} - {2}", NumericalCode, CompanyCode, Company);
        }

        public string FormatWaggonNumber()
        {
            return string.Format("{0:0#} {1}", NumericalCode, CompanyCode);
        }
    }
}
